package com.lizx.persional.common.config;

import com.baomidou.kisso.SSOAuthorization;
import com.baomidou.kisso.web.interceptor.SSOPermissionInterceptor;
import com.baomidou.kisso.web.interceptor.SSOSpringInterceptor;
import com.lizx.persional.common.interceptor.DataLoadingInterceptor;
import com.lizx.persional.common.interceptor.MyKissoHandler;
import com.lizx.persional.service.impl.ResourcesServiceImpl;
import org.apache.tomcat.util.http.parser.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


/**
 * <p>
 * WEB 初始化相关配置
 * </p>
 *
 * @author LiZhenXing
 * @since 2017-08-08
 */
@ControllerAdvice
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private SSOAuthorization ssoAuthorization;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // kisso 拦截器配置
        SSOSpringInterceptor ssoSpringInterceptor = new SSOSpringInterceptor();
        ssoSpringInterceptor.setHandlerInterceptor(new MyKissoHandler());
        registry.addInterceptor(ssoSpringInterceptor).addPathPatterns("/persional/**").excludePathPatterns("/persional/account/**");
//        SSOPermissionInterceptor ssoPermissionInterceptor = new SSOPermissionInterceptor();
//        ssoPermissionInterceptor.setAuthorization(ssoAuthorization);
//        registry.addInterceptor(ssoPermissionInterceptor).addPathPatterns("/persional/**").excludePathPatterns("/persional/account/**");
//        registry.addInterceptor(new DataLoadingInterceptor());
    }

    /**
     * mvc config
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * swagger
         */
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

        /**
         * persional
         */
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/views/");
    }


}
